package com.yuwenchao.superafflatus.controller;


import com.yuwenchao.superafflatus.constant.AfflatusConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "多功能计算")
@RestController
public class SuperCalculateController {
	

	 @ApiOperation("复利计算器")
	 @RequestMapping(value="commandInterest",method= RequestMethod.POST)
		public double getCommandInterest(
			@ApiParam(value = "本金(元)", required = true)@RequestParam(value="money") double money,
			@ApiParam(value = "利率（%）", required = true)@RequestParam(value="interest") double interest,
			@ApiParam(value = "年限(年)", required = true)@RequestParam(value="years")  int years) {
	    	interest =interest/100;
			double futureValue = money* Math.pow(1+interest, years);
			//保留三位小数
			futureValue=(double)Math.round(futureValue*1000)/1000;
			//System.out.println("最终复利值为(四舍五入保留三位小数)"+futureValue);
			return futureValue;
		}
	    

		@ApiOperation("利息计算器")
	    @RequestMapping(value="dailyInterest",method= RequestMethod.POST)
		public double getdailyInterest(
				@ApiParam(value = "本金(元)", required = true)@RequestParam(value="lixiMoney") double lixiMoney,
				@ApiParam(value = "利率（%）", required = true)@RequestParam(value="lixiInterest") double lixiInterest,
				@ApiParam(value = "天数(天)", required = true)@RequestParam(value="days")  int days) {
			lixiInterest =lixiInterest/100;
			double futureValue =lixiInterest/365*lixiMoney*days;
			//保留三位小数
			futureValue=(double)Math.round(futureValue*1000)/1000;
				//System.out.println("最终复利值为(四舍五入保留三位小数)"+futureValue);
			return futureValue;
		}
	    
	    
	    

		@ApiOperation("收益差值计算器")
	    @RequestMapping(value="contrastlixi",method= RequestMethod.POST)
		public double contrastlixi(
				@ApiParam(value = "本金(元)", required = true)@RequestParam(value="contrastmoney") double contrastmoney,
				@ApiParam(value = "初利率（%）", required = true)@RequestParam(value="contrastinterest1") double contrastinterest1,
				@ApiParam(value = "终利率（%）", required = true)@RequestParam(value="contrastinterest2") double contrastinterest2,
				@ApiParam(value = "天数(天)", required = true)@RequestParam(value="contrastdays")  int contrastdays) {
	    	contrastinterest1 =contrastinterest1/100;
	    	contrastinterest2=contrastinterest2/100;
			double futureValue =(contrastinterest2-contrastinterest1)/365*contrastmoney*contrastdays;
			//保留三位小数
			futureValue=(double)Math.round(futureValue*1000)/1000;
				//System.out.println("最终复利值为(四舍五入保留三位小数)"+futureValue);
			return futureValue;
		}
	    
	    
	    
	    //定投公式  M=a(1+x)[-1+(1+x)^n]/x

		@ApiOperation("定投计算器")
	    @RequestMapping(value="dingtou",method= RequestMethod.POST)
		public double dingtou(
				@ApiParam(value = "本金(元)", required = true)@RequestParam(value="dongtoumoney") double dongtoumoney,
				@ApiParam(value = "利率（%）", required = true)@RequestParam(value="dingtouinterest") double dingtouinterest,
				@ApiParam(value = "年限（年）", required = true)@RequestParam(value="dingyears")  int dingyears) {
	    	dingtouinterest =dingtouinterest/100;
			double futureValue =dongtoumoney*12*(1+dingtouinterest)*(-1+Math.pow(1+dingtouinterest, dingyears))/dingtouinterest;
			//保留三位小数
			futureValue=(double)Math.round(futureValue*1000)/1000;
				//System.out.println("最终复利值为(四舍五入保留三位小数)"+futureValue);
			return futureValue;
		}
	    
	    

		@ApiOperation("收益率计算器")
	    @RequestMapping(value="shouyilv",method= RequestMethod.POST)
		public double shouyilv(
				@ApiParam(value = "本金(元)", required = true)@RequestParam(value="bjmoney") double bjmoney,
				@ApiParam(value = "收益金(元)", required = true)@RequestParam(value="sylmoney") double sylmoney,
				@ApiParam(value = "天数(天)", required = true)@RequestParam(value="syldays")  int syldays) {

			double futureValue =sylmoney/syldays/bjmoney*365*100;
			//保留三位小数
			futureValue=(double)Math.round(futureValue*1000)/1000;
				//System.out.println("最终复利值为(四舍五入保留三位小数)"+futureValue);
			return futureValue;
		}



	@ApiOperation("财务自由计算")
	@RequestMapping(value="freedom",method=RequestMethod.POST)
	public double getdailyInterest(@RequestParam(value="freedomMoney") double freedomMoney) {

		double futureValue =freedomMoney*12/0.042;
		//保留三位小数
		futureValue=(double)Math.round(futureValue*1000)/1000;
		//System.out.println("最终复利值为(四舍五入保留三位小数)"+futureValue);
		return futureValue;
	}



	@ApiOperation("日期相差天数")
	@PostMapping("getdays")
	public int getdays(@RequestParam(value="startDate")String startDate,
					   @RequestParam(value="endDate")String endDate) throws ParseException {
		SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date fromDate1 = simpleFormat.parse(startDate);
		Date toDate1 = simpleFormat.parse(endDate);
		long from1 = fromDate1.getTime();
		long to1 = toDate1.getTime();
		int days = (int) ((to1 - from1) / (1000 * 60 * 60 * 24));
		// System.out.println("两个时间之间的天数差为：" + days+"天");

	  		/*	小时差
	      Date fromDate2 = simpleFormat.parse("2018-03-01 12:00");
	      Date toDate2 = simpleFormat.parse("2018-03-12 12:00");
	      long from2 = fromDate2.getTime();
	      long to2 = toDate2.getTime();
	      int hours = (int) ((to2 - from2) / (1000 * 60 * 60));
	      System.out.println("两个时间之间的小时差为：" + hours);

	       	分钟差
	      Date fromDate3 = simpleFormat.parse("2018-03-01 12:00");
	      Date toDate3 = simpleFormat.parse("2018-03-12 12:00");
	      long from3 = fromDate3.getTime();
	      long to3 = toDate3.getTime();
	      int minutes = (int) ((to3 - from3) / (1000 * 60));
	      System.out.println("两个时间之间的分钟差为：" + minutes);*/
		return  days;
	}


	    
}
